package com.qsboss.demo.controller;

import com.qsboss.demo.domain.Result;
import com.qsboss.demo.pojo.TbRole;
import com.qsboss.demo.service.TbRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 军哥
 * @version 1.0
 * @description: 角色管理控制层
 * @date 2023/10/28 9:43
 */

@RestController
@Slf4j
@RequestMapping(value = "/role")
public class TbRoleController {

    @Autowired
    TbRoleService tbRoleService;

    @RequestMapping(value = "/clearRoleCache")
    public Result clearRoleCache() {
        tbRoleService.clearRoleCache();

        return Result.SUCCESS();
    }

    @RequestMapping(value = "/getRoleById")
    public Result getRoleById(Integer roleId) {
        TbRole tbRole = tbRoleService.getRoleById(roleId);
        if(tbRole == null) {
            return Result.FAILED(404, "角色不存在");
        }

        return Result.SUCCESS(tbRole);
    }

    @RequestMapping(value = "/getRoleList")
    public Result getRoleList() {
        List<TbRole> roleList = tbRoleService.getRoleList();

        return Result.SUCCESS(roleList);
    }

}
